package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.DataConfigDAO;
import com.xinghou.platform.model.main.DataConfig;

/**
 * @author zhen.xu
 *
 */
@Service
public class DataConfigDAOImpl {/*
	@Resource
	private JdbcTemplate jdbcTemplate;

	@Override
	public DataConfig getDataConfigByTag_id(Integer tagId, Integer tagType)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
	    String sql = "SELECT Tag_id, Tag_Type, NAME, Content FROM data_config where Tag_id = ? AND Tag_Type = ?";
	    DataConfig dataConfig = jdbcTemplate.queryForObject(sql, new Object[] { tagId ,tagType}, new DataConfigMapper());
	    CustomerContextHolder.clearCustomerType();
		return dataConfig;
	}

	@Override
	public List<DataConfig> getDataConfigList(Integer tagType)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Tag_id, Tag_Type, NAME, Content FROM data_config where Tag_Type = ?";
	    List<DataConfig> list= jdbcTemplate.query(sql,new Object[] { tagType},new DataConfigMapper());
		return list;
	}
	
	private static final class DataConfigMapper implements RowMapper<DataConfig> {
		public DataConfig mapRow(ResultSet rs, int rowNum) throws SQLException {
			DataConfig dataConfig = new DataConfig();
			dataConfig.setName(rs.getString("NAME"));
			dataConfig.setTagId(rs.getInt("Tag_id"));
			dataConfig.setTagType(rs.getInt("Tag_Type"));
			dataConfig.setContent(rs.getString("Content"));
			return dataConfig;
		}
	}*/

}
